﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;

public class InputController : MonoBehaviour
{

    public GameObject m_3DMenuButtons;
    private bool isShow3DMenu;
    public Transform m_3DMenuPos;
    public delegate void OnMenuButtonPressHandler();
    public event OnMenuButtonPressHandler onMenuShow;
    public event OnMenuButtonPressHandler onMenuHide;
    private VRTK_Pointer pointer;
    


    void Start()
    {
        pointer = GetComponent<VRTK_Pointer>();
        m_3DMenuButtons.SetActive(false);
        GetComponent<VRTK_ControllerEvents>().ButtonTwoPressed += new ControllerInteractionEventHandler(DoStartMenuPressed);
        GetComponent<VRTK_ControllerEvents>().ButtonOnePressed += new ControllerInteractionEventHandler(DoStartMenuPressed);
        //初始化手柄为贝塞尔曲线
        Set3DMenu(false);
    }

    private void DoStartMenuPressed(object sender, ControllerInteractionEventArgs e)
    {
        isShow3DMenu = !isShow3DMenu;
        Set3DMenu(isShow3DMenu);
    }


    /// <summary>
    /// 显示3D按钮菜单
    /// </summary>
    /// <param name="isShow"></param>
    void Set3DMenu(bool isShow)
    {
        m_3DMenuButtons.SetActive(isShow);
        m_3DMenuButtons.transform.position = m_3DMenuPos.position;
        m_3DMenuButtons.transform.localEulerAngles = m_3DMenuPos.eulerAngles;
        if (isShow == true)
        {
            pointer.pointerRenderer = GetComponent<VRTK_StraightPointerRenderer>();
            pointer.enableTeleport = false;
            if (onMenuHide != null)
            {
                onMenuShow();
            }
        }
        else
        {
            pointer.pointerRenderer = GetComponent<VRTK_BezierPointerRenderer>();
            pointer.enableTeleport = true;
            if (onMenuHide!=null)
            {
                onMenuHide();
            }
        }
    }


    /// <summary>
    /// 禁用手柄瞬移
    /// </summary>
    public  void DisAbleTeleProt()
    {
        pointer.enableTeleport = false;
    }
}
